/**
 * Copyright (C) 2013 The yydorid-framework project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.yangying.androidframework.core.model;

import net.yangying.androidframework.util.ParcelUtils;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * app类
 * 
 * @author yangying
 * @date 2013-1-10 下午1:15:08
 * @version 1.0
 *
 */
public class App implements YYDroid,Parcelable{
	
	/**
	 * id
	 */
	private String id;
	/**
	 * app名称
	 */
	private String name;
	/**
	 * 简介
	 */
	private String desc;
	/**
	 * 详情
	 */
	private String detail;
	/**
	 * img url
	 */
	private String img;
	/**
	 * down url
	 */
	private String url;
	/**
	 * 排序 递增显示
	 */
	private int order;
	
	/**
	 * app详情中的展示图片列表
	 */
	private Group<AppImage> appImages;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Group<AppImage> getAppImages() {
		return appImages;
	}

	public void setAppImages(Group<AppImage> appImages) {
		this.appImages = appImages;
	}

	public App(){
		appImages = new Group<AppImage>();
	}
	
	private App(Parcel in) {
		appImages = new Group<AppImage>();
		id = ParcelUtils.readStringFromParcel(in);
		name = ParcelUtils.readStringFromParcel(in);
		desc = ParcelUtils.readStringFromParcel(in);
		detail = ParcelUtils.readStringFromParcel(in);
		img = ParcelUtils.readStringFromParcel(in);
		url = ParcelUtils.readStringFromParcel(in);
		order = in.readInt();
		int appImagesNum = in.readInt();
        for (int i = 0; i < appImagesNum; i++) {
        	AppImage appImage = in.readParcelable(AppImage.class.getClassLoader());
        	appImages.add(appImage);
        }
		
	}
	@Override
	public int describeContents() {
		return 0;
	}
	
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		ParcelUtils.writeStringToParcel(dest, id);
		ParcelUtils.writeStringToParcel(dest, name);
		ParcelUtils.writeStringToParcel(dest, desc);
		ParcelUtils.writeStringToParcel(dest, detail);
		ParcelUtils.writeStringToParcel(dest, img);
		ParcelUtils.writeStringToParcel(dest, url);
		dest.writeInt(order);
		dest.writeInt(appImages.size());
        for (AppImage it : appImages) {
            dest.writeParcelable(it, flags);
        }
	}
	
    public static final Parcelable.Creator<App> CREATOR = new Parcelable.Creator<App>() {
        public App createFromParcel(Parcel in) {
            return new App(in);
        }

        @Override
        public App[] newArray(int size) {
            return new App[size];
        }
    };
	
}
